﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SmartSpace.Core;
using SsTool.Common;

namespace SsTool.Base.Windows
{
    /// <summary>
    /// Interaction logic for NavigationWindow.xaml
    /// </summary>
    public partial class NavigationWindow : Window
    {
        public Navigation Navigation { get; private set; }

        public NavigationWindow(Navigation parent, int index)
        {
            InitializeComponent();

            Navigation = new Navigation();
            Navigation.Id = Guid.NewGuid();
            if (parent != null)
            {
                Navigation.ParentId = parent.Id;
            }

            this.DataContext = Navigation;
        }

        public NavigationWindow(Navigation navigation)
        {
            InitializeComponent();

            Navigation = navigation;

            this.DataContext = Navigation;
        }

        private void TextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            SelectViewWindow window = new SelectViewWindow();
            if (window.ShowDialog() == true)
            {
                Navigation.ViewId = window.SelectedView.Id;
                this.DataContext = null;
                this.DataContext = Navigation;
            }
        }

        private void _ctlSubmit_Click(object sender, RoutedEventArgs e)
        {
            ICoreService service = App.Get<ICoreService>();
            if (service.StoreNavigation(Navigation) == true)
            {
                DialogResult = true;
            }
        }

        private void _ctlBtnSelectActivity_Click(object sender, RoutedEventArgs e)
        {
            SelectActivityWindow window = new SelectActivityWindow();
            if (window.ShowDialog() == true)
            {
                Navigation.Arguments = string.Format("workflowid={0}&activityid={1}",
                   window.SelectedActivity.Workflow.Id,
                   window.SelectedActivity.Id);
                this.DataContext = null;
                this.DataContext = Navigation;
            }
        }
    }
}
